home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / WSKSOCKM.H < prev   
C/C++ Source or Header  |  1997-05-06  |  4KB  |  182 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.12  $
  6. //
  7. // Winsock for OWL subsystem.
  8. // Based on work by Paul Pedriana, 70541.3223@compuserve.com
  9. //----------------------------------------------------------------------------
  10. #if !defined(OWL_WSKSOCKM_H)
  11. #define OWL_WSKSOCKM_H
  12.  
  13. #if !defined(OWL_DEFS_H)
  14. # include <owl/defs.h>
  15. #endif
  16. #if !defined (_WINSOCKAPI_)
  17. # include <winsock.h>
  18. #endif
  19.  
  20. #if defined(BI_NAMESPACE)
  21. namespace OWL {
  22. #endif
  23.  
  24. // Generic definitions/compiler options (eg. alignment) preceeding the 
  25. // definition of classes
  26. #include <services/preclass.h>
  27.  
  28. //
  29. // class TSocketInfo
  30. // ~~~~~ ~~~~~~~~~~~
  31. // TSocketInfo encapsulates the structure that contains details of the
  32. // Windows Socket implementation. For example, it contains the version
  33. // of the Windows Socket specification implemented, the maximum number of
  34. // sockets that a single process can open etc. etc.
  35. //
  36. class _OWLCLASS TSocketInfo : public WSAData {
  37.   public:
  38.     TSocketInfo();
  39. };
  40.  
  41. //
  42. // class TSocketManager
  43. // ~~~~~ ~~~~~~~~~~~~~~
  44. // A class that starts up WinSock and provides information about
  45. // the system's WinSock.
  46. //
  47. class _OWLCLASS TSocketManager {
  48.   public:
  49.     TSocketManager(short versionMajor = 1, short versionMinor = 1,
  50.                    bool autoStartup = true);
  51.     virtual ~TSocketManager();
  52.  
  53.     void Init(short versionMajor = 1, short versionMinor = 1);
  54.  
  55.     int Startup();
  56.     int ShutDown();
  57.  
  58.     int       IsAvailable();
  59.     int       GetMajorVersion();
  60.     int       GetMinorVersion();
  61.     char*     GetDescription();
  62.     char*     GetSystemStatus();
  63.     ushort    GetMaxUdpDgAvailable();
  64.     ushort    GetMaxSocketsAvailable();
  65.     char far* GetVendorInfo();
  66.     int       GetLastError();
  67.     void      Information(TSocketInfo& socketInfo);
  68.  
  69.   protected:
  70.     int          LastError;      // Last error code
  71.     short        Available;      // Flag for Winsock availability
  72.     short        StartupCount;   // Make sure to not overflow number of connects
  73.     TSocketInfo  SocketInfo;     // Information about this WinSocket implementation
  74.     short        VersionMajor;   // Major verion number
  75.     short        VersionMinor;   // Minor verion number
  76. };
  77.  
  78. // Generic definitions/compiler options (eg. alignment) following the 
  79. // definition of classes
  80. #include <services/posclass.h>
  81.  
  82. #if defined(BI_NAMESPACE)
  83. } // namespace OWL
  84. #endif
  85.  
  86. //----------------------------------------------------------------------------
  87. // Inline implementations
  88. //
  89.  
  90. //
  91. // Return true if WinSock is available.
  92. //
  93. inline int
  94. TSocketManager::IsAvailable()
  95. {
  96.   return Available;
  97. }
  98.  
  99. //
  100. // Return the major version of WinSock support.
  101. //
  102. inline int
  103. TSocketManager::GetMajorVersion()
  104. {
  105.   return VersionMajor;
  106. }
  107.  
  108. //
  109. // Return the minor version of WinSock support.
  110. //
  111. inline int
  112. TSocketManager::GetMinorVersion()
  113. {
  114.   return VersionMinor;
  115. }
  116.  
  117. //
  118. // Return the system's description of WinSock.
  119. //
  120. inline char*
  121. TSocketManager::GetDescription()
  122. {
  123.   return SocketInfo.szDescription;
  124. }
  125.  
  126. //
  127. // Return the status of WinSock.
  128. //
  129. inline char*
  130. TSocketManager::GetSystemStatus()
  131. {
  132.   return SocketInfo.szSystemStatus;
  133. }
  134.  
  135. //
  136. // Return maximum number of bytes each UDP packet can be.
  137. //
  138. inline ushort
  139. TSocketManager::GetMaxUdpDgAvailable()
  140. {
  141.   return SocketInfo.iMaxUdpDg;
  142. }
  143.  
  144. //
  145. // Return maximum number of WinSock connections avaialble.
  146. //
  147. inline ushort
  148. TSocketManager::GetMaxSocketsAvailable()
  149. {
  150.   return SocketInfo.iMaxSockets;
  151. }
  152.  
  153. //
  154. // Return this Winsocket's vendor's information.
  155. //
  156. inline char far*
  157. TSocketManager::GetVendorInfo()
  158. {
  159.   return SocketInfo.lpVendorInfo;
  160. }
  161.  
  162. //
  163. // Return the last error code.
  164. //
  165. inline int
  166. TSocketManager::GetLastError()
  167. {
  168.   return LastError;
  169. }
  170.  
  171. //
  172. // Set the information about this WinSocket.
  173. //
  174. inline void
  175. TSocketManager::Information(TSocketInfo& socketInfo)
  176. {
  177.   socketInfo = SocketInfo;
  178. }
  179.  
  180.  
  181. #endif  // OWL_SOCKMGR_H
  182.